<?php
/**
 * 收货地址类文件
 * 作者：刘单风
 * 最后修改时间：2018-11-14
 * 版权：医库PHP小组
 */

namespace app\model;
use app\model\modelbase\IBasemodel;
use think\Model;
use think\Db;

class Address extends Model implements IBasemodel
{
    //获取收货地址列表
    function dataList($where)
    {
        //读取默认地址
        $defdata = Db::table('luck_address')
            ->where($where)
            ->where('is_default', 1)
            ->where('is_logicdel', 0)
            ->select();
        $data = Db::table('luck_address')
            ->where($where)
            ->where('is_default', 0)
            ->where('is_logicdel', 0)
            ->order('id desc')
            ->select();
        $data = array_merge($defdata, $data);
        return $data;
    }

    //新增收货地址
    function addOne($data)
    {
        $id = Db::table('luck_address')
            ->insertGetId($data);
        return $id;
    }

    //更新收货地址
    function updateOne($data,$where)
    {
        Db::table('luck_address')
            ->where($where)
            ->update($data);
        return 0;
    }

    //获取收货地址
    function oneDetail($where)
    {
        $data = Db::table('luck_address')
            ->where($where)
            ->find();
        return $data;
    }

    //删除收货地址
    function deleteOne($where)
    {
        Db::table('luck_address')
            ->where($where)
            ->delete();
        return 0;
    }

    //收货地址是否存在
    function isExist($where)
    {
        $data = Db::table('luck_address')
            ->where($where)
            ->find();
        return $data;
    }
}